package org.gd.hellojson.jackson.wrap;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.node.ObjectNode;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Gorhover
 * @version 1.0-SNAPSHOT
 * @since 2013-09-23 09:42
 */
class App {

    public static void main(String[] args) throws IOException {
        User user = new User();
        user.setId(1);
        user.setName("user name");
        ObjectMapper mapper = new ObjectMapper();

        Map<String, User> userWrapper = new HashMap<>();
        userWrapper.put("user", user);

        String json = mapper.writeValueAsString(userWrapper);
        System.out.println(json);

        JsonNode node = mapper.readValue(json, JsonNode.class).get("user");
        System.out.println(node);
        user = mapper.readValue(node, User.class);
        System.out.println(user);
    }
}
